More implementation for NEWQ.
authortsteven4@gmail.com <tsteven4@gmail.com@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Mon, 17 Feb 2014 15:16:34 +0000 (15:16 +0000)
committertsteven4@gmail.com <tsteven4@gmail.com@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Mon, 17 Feb 2014 15:16:34 +0000 (15:16 +0000)
git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@4749 f51c46e8-681c-474f-0cfe-069cfd0219fb

gpsbabel/garmin.cc
gpsbabel/lowranceusr4.cc
gpsbabel/radius.cc
gpsbabel/tomtom.cc
gpsbabel/waypt.cc

index d5dd6a297b928e45670a0f33ba903d3dfad63de9..5d1a9d6cdb476818a96324440d5afda58241d72e 100644 (file)
@@ -885,8 +885,12 @@ waypoint_prepare(void)
 {
   int i;
   int n = waypt_count();
+#if NEWQ
+  extern QList<Waypoint*> waypt_list;
+#else
   queue* elem, *tmp;
   extern queue waypt_head;
+#endif
   int icon;
 
   tx_waylist = (struct GPS_SWay**) xcalloc(n,sizeof(*tx_waylist));
@@ -897,12 +901,16 @@ waypoint_prepare(void)
 
   i = 0;
 
+#if NEWQ
+  // Iterate with waypt_disp_all?
+  foreach(Waypoint* wpt, waypt_list) {
+#else
   QUEUE_FOR_EACH(&waypt_head, elem, tmp) {
-    Waypoint* wpt;
+    Waypoint* wpt = (Waypoint*) elem;
+#endif
     char* ident;
     char obuf[256];
 
-    wpt = (Waypoint*) elem;
 #if NEW_STRINGS 
     QString src;
     if (!wpt->description.isEmpty()) {
index e7a492c937e9e22c1f53f9185483b9c368af4605..94d72ba612acf448b91d028db8b71f4335e52940 100644 (file)
 
 /* from waypt.c, we need to iterate over waypoints when extracting
    routes */
+#if NEWQ
+extern QList<Waypoint*> waypt_list;
+#else
 extern queue waypt_head;
+#endif
 
 static gbfile* file_in;
 static gbfile* file_out;
@@ -473,12 +477,18 @@ lowranceusr4_parse_waypoints(void)
 static Waypoint*
 lowranceusr4_find_waypt(int uid_unit, int uid_seq_low, int uid_seq_high)
 {
+#if !NEWQ
   queue* elem, *tmp;
-  Waypoint* waypointp;
+#endif
   lowranceusr4_fsdata* fs = NULL;
 
+#if NEWQ
+  // Iterate with waypt_disp_all?
+  foreach(Waypoint* waypointp, waypt_list) {
+#else
   QUEUE_FOR_EACH(&waypt_head, elem, tmp) {
-    waypointp = (Waypoint*) elem;
+    Waypoint* waypointp = (Waypoint*) elem;
+#endif
     fs = (lowranceusr4_fsdata*) fs_chain_find(waypointp->fs, FS_LOWRANCEUSR4);
 
     if (fs && fs->uid_unit == uid_unit &&
index 840148d46b7594d6e10894c90724d34e729bcac4..a177aad2f20ef97ef2a649deae96395d6eddaeef 100644 (file)
@@ -109,8 +109,9 @@ dist_comp(const void* a, const void* b)
 void
 radius_process(void)
 {
+#if !NEWQ
   queue* elem, * tmp;
-  Waypoint* waypointp;
+#endif
   double dist;
   Waypoint** comp;
   int i, wc;
@@ -120,7 +121,7 @@ radius_process(void)
   foreach(Waypoint* waypointp, waypt_list) {
 #else
   QUEUE_FOR_EACH(&waypt_head, elem, tmp) {
-    waypointp = (Waypoint*)elem;
+    Waypoint* waypointp = (Waypoint*)elem;
 #endif
     dist = gc_distance(waypointp->latitude,
                        waypointp->longitude,
@@ -154,8 +155,12 @@ radius_process(void)
    * for qsort.
    */
 
+#if NEWQ
+  foreach(Waypoint* wp, waypt_list) {
+#else
   QUEUE_FOR_EACH(&waypt_head, elem, tmp) {
     Waypoint* wp = (Waypoint*) elem;
+#endif
     comp[i] = wp;
     waypt_del(wp);
     i++;
index d6ffbcba7028d240f5a493ba8e8768145248fdad..22b55cead45ad52d16fa425fca84fef2a0ba2ce4 100644 (file)
@@ -434,9 +434,12 @@ data_write(void)
 {
   int ct = waypt_count();
   struct hdr* htable, *bh;
+#if NEWQ
+  extern QList<Waypoint*> waypt_list;
+#else
   queue* elem, *tmp;
   extern queue waypt_head;
-  Waypoint* waypointp;
+#endif
   double minlon = 200;
   double maxlon = -200;
   double minlat = 200;
@@ -446,8 +449,13 @@ data_write(void)
   htable = (struct hdr*) xmalloc(ct * sizeof(*htable));
   bh = htable;
 
+#if NEWQ
+  // Iterate with waypt_disp_all?
+  foreach(Waypoint* waypointp, waypt_list) {
+#else
   QUEUE_FOR_EACH(&waypt_head, elem, tmp) {
-    waypointp = (Waypoint*) elem;
+    Waypoint* waypointp = (Waypoint*) elem;
+#endif
     bh->wpt = waypointp;
     if (waypointp->longitude > maxlon) {
       maxlon = waypointp->longitude;
index 27385e3e09aba913953a562428809e383dff0fad..9425edc5c8977e755ca4f707e03786bbd21b6555 100644 (file)
@@ -122,7 +122,7 @@ waypt_add(Waypoint* wpt)
       wpt->shortname = wpt->notes;
     } else {
       QString n;
-      n.sprintf("%03d", waypt_ct);
+      n.sprintf("%03d", waypt_count());
       wpt->shortname = QString("WPT%1").arg(n);
     }
   }
@@ -144,7 +144,9 @@ waypt_add(Waypoint* wpt)
 void
 waypt_del(Waypoint* wpt)
 {
+  // the wpt must be on waypt_list, and is assumed unique.
 #if NEWQ
+  waypt_list.removeOne(wpt);
 #else
   dequeue(&wpt->Q);
   waypt_ct--;
@@ -221,7 +223,7 @@ waypt_disp_session(const session_t* se, waypt_cb cb)
     if ((se == NULL) || (waypointp->session == se)) {
       if (global_opts.verbose_status) {
         i++;
-        waypt_status_disp(waypt_ct, i);
+        waypt_status_disp(waypt_count(), i);
       }
       (*cb)(waypointp);
     }
@@ -324,8 +326,16 @@ find_waypt_by_name(const QString& name)
 void
 waypt_flush(queue* head)
 {
-  while (!waypt_list.isEmpty()) {
-    delete waypt_list.takeFirst();
+// TODO: This is incorrect when head != &waypt_head
+// We need to pass in a QList<Waypoint*> instead of a queue* that we ignore!
+  if (head != &waypt_head) {
+    if (global_opts.debug_level >= 1) {
+      warning("NEWQ version of waypt_flush is unimplemented for this list.\n");
+    }
+  } else {
+    while (!waypt_list.isEmpty()) {
+      delete waypt_list.takeFirst();
+    }
   }
 }
 #else
@@ -351,6 +361,8 @@ waypt_flush_all()
     mkshort_del_handle(&mkshort_handle);
   }
 #if NEWQ
+  // TODO: eventually we shoud pass the list instead of the queue.
+  waypt_flush(&waypt_head);
 #else
   waypt_flush(&waypt_head);
 #endif